package com.bss.converter;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.andy.basics.Converter;
import com.andy.basics.Dao;
import com.bss.dao.RoomDao;
import com.bss.model.Room;

@Component
public class RoomConverter extends Converter<Room> {

	@Autowired
	private RoomDao roomDao;

	@Override
	public Dao<Room> getDao() {
		return this.roomDao;
	}

	@Override
	public String asString(final Room room) {
		if (room == null) {
			return null;
		}
		return room.getRoomNumber();
	}

	@Override
	public Room asObject(final String value) {
		Converter.rootLogger.info("Room Converter called roomNumber is " + value);
		if (null == value || value.equals("0")) {
			return null;
		}
		List<Room> rooms = getDao().find("roomNumber='" + value + "'");
		if (rooms == null || rooms.size() <= 0) {
			return null;
		}
		return rooms.get(0);
	}
}
